package flst.ipiweb.service;

import java.util.ArrayList;
import java.util.List;

import flst.ipiweb.common.PromotionalCode;
import flst.ipiweb.dao.DAOFactory;
import flst.ipiweb.exceptions.IPIWebException;

public class ServiceCodePromo {

	public List<PromotionalCode> listerCodesPromo(){
		
		try {
			List<PromotionalCode> list = DAOFactory.getCodeDAO().listerCodes();
			return list;
		} catch (IPIWebException e) {
			return new ArrayList<PromotionalCode>();
		}
		
	}
	
	public PromotionalCode getCodeById(int idCode){
		
		try {
			return DAOFactory.getCodeDAO().getCodeById(idCode);
		} catch (IPIWebException e) {
			return new PromotionalCode();
		}
	}

	public boolean codeIsExist(String codePromo){
		
		try {
			return DAOFactory.getCodeDAO().codeIsExist(codePromo);
		} catch (IPIWebException e) {
			return false;
		}
	}
	
	public int referenceExist(String reference){
		try {
			return DAOFactory.getCodeDAO().referenceExist(reference);
		} catch (IPIWebException e) {
			return 0;
		}
	}
	
	public void deleteCode(PromotionalCode code){
	
		try {
			 DAOFactory.getCodeDAO().deleteCode(code);
		} catch (IPIWebException e) {
			
		}
	}

	
	public void createCode(PromotionalCode code){
		
		try {
			DAOFactory.getCodeDAO().createCode(code);
		} catch (IPIWebException e) {

		}
		
	}
	
	public void majCode(PromotionalCode code){
  	  try {
			DAOFactory.getCodeDAO().majCode(code);
		} catch (IPIWebException e) {
		
		}
    } 
	
}
